// pages/classify/classify.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    no_pic:'/static/images/empty/home_cate.png',
    tabbar: [],
    height: 0, //scroll-view高度
    top: 0,
    currentTab: 0, //预设当前项的值
    scrollViewId:"id_0"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    setTimeout(() => {
			wx.getSystemInfo({
				success: res => {
					let header = 92/2;
					let top = 0;
          this.setData({
            height: res.windowHeight - header,
            top: top + header
          })
				}
			});
		}, 50);
		this.load();
  },
  adAction(e){
    let s=e.currentTarget.dataset.item;
    wx.util.bannerAc(s);
  },
  async load(){
    let res=await wx.util.post("cate/index");
    this.setData({
      tabbar: res.data
    });
  },
  // 点击标题切换当前页时改变样式
  swichNav: function(e) {
    let cur = e.currentTarget.dataset.current;
    if (this.currentTab == cur) {
      return false;
    } else {
      this.setData({
        currentTab: cur
      });
      this.checkCor();
    }
  },
  //判断当前滚动超过一屏时，设置tab标题滚动条。
  checkCor: function() {
    let abc='';
    if (this.currentTab > 6) {
      abc = `id_${this.currentTab - 2}`;
    } else {
      abc = `id_0`;
    }
    this.setData({
      scrollViewId:abc
    });
  },
  productList(e) {
    let key = e.currentTarget.dataset.key;
    let id = e.currentTarget.dataset.id;
    let fid = e.currentTarget.dataset.fid;
    wx.navigateTo({
      url: '../classify/cate?fid='+fid+'&n=' + key+'&id='+id
    });
  },
  productList2(e) {
    let key = e.currentTarget.dataset.key;
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../list/list?searchKey=' + key+'&id='+id
    });
  },
  search: function() {
    wx.navigateTo({
      url: '../search/search'
    });
  },
  onShareAppMessage: function (e) {
		let wxid=wx.getStorageSync("openid") || '';
	    return {
		  path: '/pages/classify/classify?wxid='+wxid,
		}
	},
	onShareTimeline: function (e) {
		let wxid=wx.getStorageSync("openid") || '';
	    return {
		  query: 'wxid='+wxid,
		}
	}
})